﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LittleBee.CellStore.UserControls
{
    public partial class UCCommSettings : UserControl
    {
        public UCCommSettings()
        {
            InitializeComponent();
        }

		private void UCCommSettings_Load(object sender, EventArgs e)
		{
			if (Tag == null)
				return;

            StoreCell cell = (Tag as StoreCell)!;
            tbCommSettings.Text = cell.CommSet.ToString();
        }

		private void UCCommSettings_Leave(object sender, EventArgs e)
		{
            UpdateSettings();
		}

		private void UpdateSettings(Control? updateControl = null)
		{
			if (Tag == null)
				return;

			StoreCell cell = (Tag as StoreCell)!;

			if (updateControl == null)
			{
				cell.CommSet = JObject.Parse(tbCommSettings.Text);
			}
			else
			{
				if (updateControl.Name == tbCommSettings.Name)
				{
					cell.CommSet = JObject.Parse(tbCommSettings.Text);
				}
			}
		}
	}
}
